package com.javadaemon.Tinderbox.gui;

import com.javadaemon.Tinderbox.Tinderbox;
import com.javadaemon.Tinderbox.model.Misc;
import java.awt.KeyEventDispatcher;
import java.awt.event.KeyEvent;

/**
 * This file is part of Tinderbox.
 *
 * Tinderbox is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Ponix is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Tinderbox.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * This class is for handling the hotkeys of the application.
 * @author Mads Horndrup
 */
public class HotkeyListener implements KeyEventDispatcher {

    Tinderbox parent;

    public HotkeyListener(Tinderbox parent) {
        this.parent = parent;
    }

    @Override
    public boolean dispatchKeyEvent(KeyEvent e) {
        if (e.getID() == KeyEvent.KEY_PRESSED) {
            switch (e.getKeyCode()) {
                case KeyEvent.VK_F10:
                    parent.toggleFullscreen();
                    break;
                case KeyEvent.VK_F9:
                    if (Tinderbox.getControlPanel() != null) {
                        Tinderbox.getControlPanel().toggleHide();
                    } else {
                        parent.initializeControlPanel();
                    }
                    break;
                case KeyEvent.VK_F11:
                    Misc.createScreenshot();
                    break;
            }
        }
        return false;
    }
}
